package bankapp.get;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class home extends Activity
{
	private EditText userid,password;
	private Button b;
	private TodoDbAdapter mDbHelper;
	 private Table table = null;
	 private Long mRowId;
	 Intent ad,user;
	 Cursor c;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        userid=(EditText)this.findViewById(R.id.htuser);
        password=(EditText)this.findViewById(R.id.htpass);
        b=(Button)this.findViewById(R.id.homelogin);
        mDbHelper = new TodoDbAdapter(this);
        mDbHelper.open();
        c=mDbHelper.fetchAllTodos();
        startManagingCursor(c);
        System.out.println("hiiiiii  username is "+userid);
        b.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {

                //setResult(RESULT_OK);
                //finish();
            	operate();             
            	
            }

        });
	}
	public void operate()
	{
		System.out.println("helllloooooooo");
		int flag=0;
    	String username="";
    	while(c.moveToNext())
        {
    		if(c.getString(1).equals(userid.getText().toString())&&c.getString(2).equals(password.getText().toString()))
    		{
    			flag=1;
    			username=c.getString(1);
    			break;
    		}
        
        }
    	System.out.println("username is "+username);
    	System.out.println("flag is "+flag);
    	
    	if(flag==1&&username.equals("admin"))
    	{
    		user=new Intent();
    		user.setClass(this, BankappActivity.class);
    		user.putExtra("user", username);
    		
        	startActivity(user);	
    	}
    	if(flag==1&&!username.equals("admin"))
    	{
    		 ad=new Intent();
    		 ad.setClass(this, BankUser.class);
    		ad.putExtra("user", username);
        	System.out.println("in if");
        	startActivity(ad);	
    	}
    	
	}
	

}
